package com.ybf.api.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import com.github.pagehelper.PageHelper;
import com.ybf.api.entity.PageRequest;
import com.ybf.api.entity.PageResult;
import com.ybf.api.entity.Permissions;
import com.ybf.api.mapper.PermissionsMapper;
import com.ybf.api.service.PermissionsService;
import com.ybf.api.utils.EncryptUtils;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ybf
 * @since 2024-09-26
 */
@Service("PermissionsService")
public class PermissionsImpl implements PermissionsService {

    @Resource
    private PermissionsMapper permissionsMapper;

    @Override
    public PageResult<Permissions> list(Permissions permissions, PageRequest pageRequest) {
        PageHelper.startPage(pageRequest);
        List<Permissions> list = permissionsMapper.list(permissions);
        PageResult<Permissions> pageResult = new PageResult<Permissions>(list);
        return pageResult;
    }

    @Override
    public Permissions info(Integer id) {
        return permissionsMapper.info(id);
    }

    @Override
    public Boolean delete(Integer id) {
        return permissionsMapper.delete(id) > 0;
    }

    @Override
    public Integer edit(Permissions permissions) {
        if (permissions.getId() != null) {
            return permissionsMapper.edit(permissions);
        }
        return permissionsMapper.add(permissions);
    }
}
